package com.authine.cloudpivot.ext.model.yunshu;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Peter Lee
 * @Date: 2021/1/20 9:48
 * @Describe: 云枢请求参数封装
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class YsRequestModel {

    /**
     * PutawayControl -> 上下架审批回写
     * EnableControl  -> 商品启禁用
     */
    @JsonProperty("ActionName")
    private String actionName;

    /**
     * GomroToH3yun_Controller -> 上下架审批回写
     * GomroToH3yun_Controller -> 商品启禁用
     */
    @JsonProperty("Controller")
    private String controller;

    /**
     * D00021SupplyChain -> 上下架审批回写
     * D00021SupplyChain -> 商品启禁用
     */
    @JsonProperty("AppCode")
    private String appCode;

    /**
     * 推送数据的json
     */
    @JsonProperty("PushDataList")
    private String pushDataList;

    /**
     * 测试使用
     *
     * @return
     * @throws JsonProcessingException
     */
    public static YsRequestModel getYs() throws JsonProcessingException {
        List<PushData> pushDataList = new ArrayList<>();
        pushDataList.add(PushData.builder().type("type1").msg("消息1").goodsId("123123").build());
        pushDataList.add(PushData.builder().type("type2").msg("消息2").goodsId("123123").build());
        ObjectMapper objectMapper = new ObjectMapper();
        return YsRequestModel.builder().actionName("PutawayControl")
                .controller("GomroToH3yun_Controller")
                .appCode("D00021SupplyChain")
                .pushDataList(objectMapper.writeValueAsString(pushDataList))
                .build();
    }

    /**
     * 构建上下架审批回写
     *
     * @return
     */
    public static YsRequestModel YsDropOff(List<PushData> pushDataList) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        return YsRequestModel.builder()
                .actionName("PutawayControl")
                .controller("GomroToH3yun_Controller")
                .appCode("D00021SupplyChain")
                .pushDataList(objectMapper.writeValueAsString(pushDataList))
                .build();
    }

    /**
     * 构建启禁用
     *
     * @return
     */
    public static YsRequestModel YsDisable(List<PushData> pushDataList) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        return YsRequestModel.builder()
                .actionName("EnableControl")
                .controller("GomroToH3yun_Controller")
                .appCode("D00021SupplyChain")
                .pushDataList(objectMapper.writeValueAsString(pushDataList))
                .build();
    }
}
